<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------

namespace app\api\controller\order;

use app\dict\order\OrderDict;


use app\api\service\order\OrderService;
use app\core\base\BaseApiController;
use think\Response;

class Order extends BaseApiController
{
    /**
     * 订单创建
     * @return Response
     */
    public function create()
    {
        $data = $this->request->params([
            ['cart_ids',[]],
            ['express_company_id',0],
            ['express_number',''],
            ['take_address_id',''],
        ]);
        //参数验证
        $this->validate($data, 'app\api\validate\order\Order.create');
        return success('SUCCESS', (new OrderService())->create($data));
    }

    /**
     * 订单列表
     * @return Response
     */
    public function lists()
    {
        $data = $this->request->params([
            [ 'order_no', '' ],
            [ 'status', '' ],
            [ 'status_group', '' ],
        ]);
        return success(( new OrderService() )->getPage($data));
    }

    /**
     * 订单详情
     * @param int $order_id
     * @return Response
     */
    public function detail(int $order_id)
    {
        return success(( new OrderService() )->getDetail($order_id));
    }


    /**
     * 同意协商
     * @param $id
     * @return Response
     */
    public function orderAgree($id)
    {
        return success(( new OrderService() )->agree($id));
    }

    /**
     * 拒绝协商
     * @param $id
     * @return Response
     */
    public function orderRefuse($id)
    {
        return success(( new OrderService() )->refuse($id));
    }

    /**
     * 申请寄回
     * @param $id
     * @return Response
     */
    public function orderApplyBack($id)
    {
        $data = $this->request->params([
            ['express_company_id',0],
            ['express_number',''],
            ['take_address_id',''],
        ]);
        //参数验证
        $this->validate($data, 'app\api\validate\order\Order.apply');
        return success(( new OrderService() )->apply($id,$data));
    }

    /**
     * 获取订单状态
     * @return Response
     */
    public function orderStatus()
    {
        return success(OrderDict::getStatus());
    }




    public function getPackage()
    {
        $data = $this->request->params([
            [ 'id', '' ],
            [ 'mobile', '' ],
        ]);
        return success(( new OrderService() )->getDeliveryPackage($data));
    }

    /**
     * 订单设置
     * @param $id
     * @return Response
     */
    public function getConfig()
    {
        return success(( new ConfigService() )->getConfig());
    }
}
